﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

using ZhimeiSoft.Framework.Server.Base;
using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Server.DAL.Interface;

namespace ZhimeiSoft.CharmManager.Server.DAL
{
    public class ServiceItemDetailDAL : BaseDal, IServiceItemDetailDAL
    {
        public DataSet QueryServiceItemDetail(int iServiceItemID)
        {
            string strSQL = ServiceItemDetailDAL_Const.SQL_SELECT_SERVICEITEMDETAIL;

            if (iServiceItemID != -1)
            {
                strSQL += " WHERE SERVICEITEMID=" + iServiceItemID.ToString();
            }
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            
            return DB.ExecuteDataSet(cmd);
        }

        public void DeleteServiceItemDetail(int iServiceItemID)
        {
            string strSQL = ServiceItemDetailDAL_Const.SQL_DELETE_SERVICEITEMDETAIL;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SERVICEITEMID, DbType.Int32, iServiceItemID);
            DB.ExecuteNonQuery(cmd);
        }



        public void SubmitServiceItmeDetail(DataSet ds)
        {
            DBEntityServiceItemDetail detail = new DBEntityServiceItemDetail();
            this.UpdateDataSet(ds, detail.GetTableName());
        }

        public void InsertServiceItemDetail(DBEntityServiceItemDetail entity)
        {
            string strSQL = ServiceItemDetailDAL_Const.SQL_INSERT_SERVICEITEMDETAIL;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SERVICEITEMID, DbType.Int32, entity.SERVICEITEMID);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SEQNUM, DbType.Int32, entity.SEQNUM);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SDAYS, DbType.Int32, entity.SDAYS);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SMEMO, DbType.String, entity.SMEMO);
            DB.ExecuteNonQuery(cmd);
        }

        public void UpdateServiceItemDetail(DBEntityServiceItemDetail entity)
        {
            string strSQL = ServiceItemDetailDAL_Const.SQL_UPDATE_SERVICEITEMDETAIL;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SERVICEITEMID, DbType.Int32, entity.SERVICEITEMID);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SEQNUM, DbType.Int32, entity.SEQNUM);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SDAYS, DbType.Int32, entity.SDAYS);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SMEMO, DbType.String, entity.SMEMO);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SERVICEITEMDETAILID, DbType.Int32, entity.SERVICEITEMDETAILID);
            DB.ExecuteNonQuery(cmd);
        }

        public void DeleteServiceItemDetailByID(int detailID)
        {
            string strSQL = ServiceItemDetailDAL_Const.SQL_DELETE_SERVICEITEMDETAILBYID;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            DB.AddInParameter(cmd, DBEntityServiceItemDetail.FieldName.SERVICEITEMDETAILID, DbType.Int32, detailID);
            DB.ExecuteNonQuery(cmd);
        }

    }
}
